package com.liuya.safe.policy.service;

import com.liuya.base.BaseService;
import com.liuya.common.exception.EntityExistException;
import com.liuya.db.script.UserCategory;
import com.liuya.safe.model.SafeUser;
import com.liuya.entitle.UserCategoryTestResult;
import com.liuya.safe.model.SafeRole;
import com.liuya.safe.model.SafeUserCategory;

import java.util.Collection;
import java.util.Locale;
import java.util.Map;

public interface UserCategoryManagerService extends BaseService<SafeUserCategory> {

    public void installCategories(String fileUrl, boolean overwrite);

    /**
     * Search leaf nodes which has the names in definition file. Generally,
     * before install definition xml file, find out same name queries, and ask
     * operator overwrite or not.
     *
     * @param fileUrl
     * @return Collection< String >
     */
    public Collection checkSameNameUserCategories(String fileUrl);

    public SafeUserCategory getUserCategory(String id);

    /**
     * Have likely name nodes, include leaf and non-leaf nodes.
     *
     * @param name
     * @return Collection< {@linkplain UserCategory} >
     */
    public Collection getLikelyUserCategories(String name);

    /**
     * Get all nodes, include ROOT node(id=0, pid=-1)
     *
     * @return
     */
    public Collection getAllUserCategories();

    /**
     * If the user category is a leaf node, delete it; else delete it cascade.
     *
     * @param id
     */
    public void deleteUserCategory(String id);

    public SafeUserCategory addUserCategory(String pid, String name, String description, boolean isLeaf) throws EntityExistException;

    public void updateUserCategory(String id, String name, String description) throws EntityExistException;

    public void updateUserCategory(String id, com.liuya.db.sql.xml.UserCategory content) throws EntityExistException;

    /**
     * Get user category tree, return ROOT node.
     *
     * @return
     */
    public SafeUserCategory getUserCategoryTree();

    public void moveUserCategory(String id, String newPid);

    public SafeUserCategory copyUserCategory(String sourceId, String newName, String newDescription) throws EntityExistException;

    /**
     * Create Reserved user category: role.
     *
     * @throws EntityExistException
     */
    public void addReservedUserCategory(Locale locale);

    /**
     * Create a usercatory means users who own this role.
     *
     * @param role
     * @throws EntityExistException
     */
    public void addUserCategory(SafeRole role);

    public UserCategoryTestResult testUserCategory(UserCategory scriptUserCategory, SafeUser user, Map context);
}
